/**
 * 修改方法集合
 * 使用： edit.function()
 * param: obj传this，调用该方法的对象
 *
 */
var edit = {
    initContract: function (addType) {
        // 继续编辑暂存合同/变更合同赋值
        if ((addType == "edit" || addType == "change") && !!contractId) {
            $.ajax({
                url: "/contract/info",
                data: {id: contractId},
                dataType: "json",
                type: "post",
                async: false,
                success: function (res) {
                    if (res.errcode === "0") {
                        edit.initSetValue(res.data);
                    } else if (res.errcode === "1") {
                        layer.msg(res.errmsg, function () {
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.error(XMLHttpRequest.status);
                    console.error(XMLHttpRequest.readyState);
                    console.error(textStatus);
                }
            });
        }
    },
    // 初始化暂存合同信息赋值
    initSetValue: function (data) {
        // console.log(JSON.stringify(data));

        // 初始化房间
        var rooms = data.room;
        if (!!rooms) {
            for (var i = 0; i < rooms.length; i++) {
                var room = rooms[i];
                var obj = {};
                obj.id = room.ROOM_ID;
                obj.name = room.ROOM_NUM;
                obj.area = room.ROOM_AREA;
                obj.type = room.PROPERTY_RIGHT_TYPE;
                obj.wid = room.WATER_CODE;
                obj.eid = room.ELECTRIC_CODE;
                chooseIdArray.push(room.ROOM_ID);
                chooseItemArray.push(obj);
            }
            operate.chooseRoom();
            roomType = rooms[0].PROPERTY_RIGHT_TYPE;
            change.cqChange(roomType);
            if (roomType == "1") {
                $("#contract-signing-date").attr("disabled", "disabled");
                $("#contract-rent-date").attr("disabled", "disabled");
                $("#contract-finish-date").attr("disabled", "disabled");
            }
        }

        // 初始化租户
        var contract = data.contract;
        if (contract.LEASE == 0) {
            $("input[name='COMPANY']").val(contract.COMPANY_NAME);
            $("input[name='BUSS_CODE']").val(contract.BUSINESS_LICENSE);
            $("input[name='LEG_REN']").val(contract.LEGAL_PERSON_NAME);
            $("input[name='LEG_TEL']").val(contract.LEGAL_PERSON_TEL);
        } else if (contract.LEASE == 1) {
            $("input:radio[name='TRNANTRY'][value='0']").attr('checked', 'false');
            $("input:radio[name='TRNANTRY'][value='1']").attr('checked', 'true');
            $(".company-input").hide();
            $(".person-input").show();
            $("input[name='NAME']").val(contract.COMPANY_NAME);
            $("input[name='ID_CARD']").val(contract.BUSINESS_LICENSE);
        }
        $("input[name='CONTRACT_NUM']").val(contract.CONTRACT_NUM);
        $("input[name='byname']").val(contract.BYNAME);
        $("select[name='industry']").val(contract.INDUSTRY_ID);
        $("input[name='SIGN_REN']").val(contract.SIGNER);
        $("input[name='SIGN_TEL']").val(contract.SIGNER_TEL);
        $("textarea[name='ADDRESS']").val(contract.CONTRACT_ADDRESS);

        // 初始化联系人
        var contacts = data.contact;
        if (!!contacts) {
            for (var i = 0; i < contacts.length; i++) {
                var contact = contacts[contacts.length - i - 1];
                $(".tenant-add-person span:first").click();
                $("input[name='lxr-name']").eq(i).val(contact.CONTACTS_NAME);
                $("input[name='lxr-tel']").eq(i).val(contact.CONTACTS_TEL);
            }
        }

        // 初始化附件
        var attachments = data.attachment;
        if (!!attachments) {
            var host = location.host;
            for (var i = 0; i < attachments.length; i++) {
                var attachment = attachments[i];
                var demoListView = $('#demoList');
                var tr = $(['<tr id="upload-' + (i + 1) + '">'
                    , '<td><img src="http://' + host + '/' + attachment.PATH + '" alt="' + attachment.NAME + '" class="layui-upload-img"></td>'
                    , '<td>' + attachment.NAME + '</td>'
                    , '<td>' + (attachment.SIZE / 1014).toFixed(1) + 'kb</td>'
                    , '<td><span style="color: #5FB878;">上传成功</span></td>'
                    , '<td>'
                    , '</td>'
                    , '</tr>'].join(''));
                demoListView.append(tr);

                var obj = {};
                obj.name = attachment.NAME;
                obj.size = attachment.SIZE;
                obj.ext = attachment.EXT;
                obj.url = attachment.PATH;
                uploadfiles.push(obj);
            }
        }

        // 初始化合同基础信息和备注
        $("input[name='totalArea']").val(contract.AREA);
        $("input[name='rentSinglePrice']").val(contract.RENT);
        $("select[name='unit']").val(contract.UNIT);
        unit = parseInt(contract.UNIT);   // 单位
        unitHtml = "元/㎡·天";     // 单位默认显示的文字
        switch (unit) {
            case 0:
                unitHtml = "元/㎡·天";
                break;
            case 1:
                unitHtml = "元/天";
                break;
            case 2:
                unitHtml = "元/月";
                break;
            case 3:
                unitHtml = "元/年";
                break;
            case 4:
                unitHtml = "元";
                break;
            case 5:
                unitHtml = "元/㎡·月";
                break;
        }

        if (contract.PAY_DAY_MONTH == 0) {
            $(".payMonths-btns a:first").addClass('layui-this').siblings().removeClass("layui-this");
        } else {
            $(".payMonths-btns a").removeClass("layui-this");
            switch (contract.PAY_DAY_MONTH) {
                case 1:
                    $(".payMonths-btns a").eq(1).addClass("layui-this");
                    break;
                case 3:
                    $(".payMonths-btns a").eq(2).addClass("layui-this");
                    break;
                case 6:
                    $(".payMonths-btns a").eq(3).addClass("layui-this");
                    break;
                case 12:
                    $(".payMonths-btns a").eq(4).addClass("layui-this");
                    break;
            }
            ftype = contract.PAY_DAY_MONTH;
        }
        $("input[name='payMonths']").val(contract.PAYMENT_PERIOD);
        $("select[name='fkrq']").val(contract.PAY_TYPE);
        $("input[name='prePayDays']").val(contract.ANT_PAY_DAY);

        // 合同签订日期、计租日期、结束日期
        $("#contract-start-date").val(contract.CON_TEN_DATE);
        $("#contract-signing-date").val(contract.CON_DATE);
        $("#contract-rent-date").val(contract.CON_HR_DATE);
        $("#contract-finish-date").val(contract.CON_END_DATE);
        $("input[name='pay-tx-days']").val(contract.PAY_TX_DAYS);
        $("input[name='end-tx-days']").val(contract.END_TX_DAYS);
        $("input[name='late-fee-days']").val(contract.LATE_FEE_DAYS);


        operate.changeDate("", "");

        // 合同前免租期
        if (!!contract.CON_OUTF_DATE) {
            $(".before-unable-rent-date").find("a").click();
            $("#before-unable-date-start").val(contract.CON_OUTF_DATE);
        }
        // 合同后免租期
        if (!!contract.CON_OUTL_DATE) {
            $(".after-unable-rent-date").find("a").click();
            $("#after-unable-date-end").val(contract.CON_OUTL_DATE);
        }

        // 初始化押金
        var bonds = data.bond;
        if (!!bonds) {
            for (var i = 0; i < bonds.length; i++) {
                var bond = bonds[i];
                if (bond.BOND_NAME == "房租押金") {
                    $("input[name='securityDepositMoney']").val(bond.BOND_MONEY);
                } else {
                    $("input[name='securityDepositMoney']").parent().parent().find(".fa-plus-circle").click();
                    $(".bond-list").find(".layui-inline:last").find("input[name='securityDepositName']").val(bond.BOND_NAME);
                    $(".bond-list").find(".layui-inline:last").find("input[name='securityDepositPrice']").val(bond.BOND_MONEY);
                }
            }
        }

        // 合同备注
        $("textarea[name='remark']").val(contract.INFO);

        // 递增类型
        if (contract.INCREAS_TYPE == 0) {
            change.rentOrdiscountOrIncreasingChange();
        } else if (contract.INCREAS_TYPE == 1) {
            $("input:radio[name='dzlx'][value='0']").attr('checked', 'false');
            $("input:radio[name='dzlx'][value='1']").attr('checked', 'true');
            change.rentOrdiscountOrIncreasingChange();
        }

        // 每年折扣
        var discounts = data.discount;
        if (!!discounts) {
            for (var i = 0; i < discounts.length; i++) {
                var discount = discounts[i];
                $(".contract-discount-body").eq(i).find("input[name='unit-rent-money']").val(discount.RENT_PRICR);
                $(".contract-discount-body").eq(i).find("input[name='unit-znj-money']").val(discount.LATE_FEE);
                $(".contract-discount-body").eq(i).find("input[name='unit-increasing']").val(discount.INCREAS_RATE);
                $(".contract-discount-body").eq(i).find("input[name='unit-discount']").val(discount.DISCOUNT);
                $(".contract-discount-body").eq(i).find(".after-discount-money").html(discount.DISCOUNT_RENT);
            }
        }

        // 付款分配
        if (contract.FKFP_TYPE == 0) {
            $("input[name='unit-fkfp']").parent().parent().find(".input-label-title").html("发票占比：");
            $("input[name='unit-fkfp']").parent().find(".input-label-unit").html("%");
        } else if (contract.FKFP_TYPE == 1) {
            $("input:radio[name='fkfp'][value='0']").attr('checked', 'false');
            $("input:radio[name='fkfp'][value='1']").attr('checked', 'true');
            $("input[name='unit-fkfp']").parent().parent().find(".input-label-title").html("发票金额：");
            $("input[name='unit-fkfp']").parent().find(".input-label-unit").html("元/期");
        }

        // 付款分配金额
        $("input[name='unit-fkfp']").val(contract.FKFP_MONEY);

        // 滞纳金比率
        $("input[name='unit-znj']").val(contract.LATE_FEE);

        // 生成租金账单
        var bill = data.bill;
        if (roomType == "0") {
            operate.createRentDetail();
        }
        // $(".container-rent-detail-list-old").html(contract.BILL_HTML);

        contractChange.setOldBill(bill);

        $(".container-rent-detail-list").html(contract.BILL_HTML);


        // 物业信息
        var propertys = data.property;
        if (!!propertys) {
            for (var i = 0; i < propertys.length; i++) {
                var property = propertys[i];

                $(".layui-input-checkbox input[name='extra']").each(function (index, d) {
                    if (property.PROPERTY_TYPE_ID == $(d).val()) {
                        $(d).attr("checked", "checked");

                        var val = property.PROPERTY_TYPE_ID;
                        var title = property.CODE;
                        var priceList;
                        // 通过物业项ID获取该物业项的所有默认价格
                        $.ajax({
                            url: "/property/propertyPriceList",
                            data: {PROPERTY_SET_ID: val},
                            dataType: "json",
                            type: "post",
                            async: false,
                            success: function (res) {
                                if (res.errcode === "0") {
                                    var data = res.data;
                                    if (!!data) {
                                        priceList = data;
                                    }
                                    form.render();
                                } else if (res.errcode === "1") {
                                    layer.msg(res.errmsg, function () {
                                    });
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                console.error(XMLHttpRequest.status);
                                console.error(XMLHttpRequest.readyState);
                                console.error(textStatus);
                            }
                        });
                        switch (val) {
                            case "a14e6f2e190e4492badac72e9b42152e":
                                $(".w-default-price-list").empty();
                                if (!!priceList) {
                                    for (var i = 0; i < priceList.length; i++) {
                                        var str = '<input type="radio" name="w-unit-price" lay-filter="w-unit-price" value="' + priceList[i].ID + '" title="' + priceList[i].PRICE_NAME + '（' + priceList[i].PRICE_TYPE + '元/吨）' + '">';
                                        $(".w-default-price-list").append(str);
                                    }
                                    form.render();
                                }
                                $(".water-content").show();
                                break;
                            case "ddcf9b35bbe04cd88834e21c1fd74f32":
                                $(".e-default-price-list").empty();
                                if (!!priceList) {
                                    for (var i = 0; i < priceList.length; i++) {
                                        var str = '<input type="radio" name="e-unit-price" lay-filter="e-unit-price" value="' + priceList[i].ID + '" title="' + priceList[i].PRICE_NAME + '（' + priceList[i].PRICE_TYPE + '元/度）' + '">';
                                        $(".e-default-price-list").append(str);
                                    }
                                    form.render();
                                }
                                $(".power-content").show();
                                break;
                            default:
                                var lnfStr = '<div class="layui-form-item">\n' +
                                    '             <div class="layui-inline">\n' +
                                    '                 <label class="layui-form-label">计费周期：</label>\n' +
                                    '                 <span style="float: left; line-height: 27px;">固定天数：</span>\n' +
                                    '                 <div style="width: 110px;" class="layui-input-inline">\n' +
                                    '                     <input type="number" name="jfzq-days" value="240" lay-verify="" autocomplete="off"\n' +
                                    '                            class="layui-input">\n' +
                                    '                     <span class="input-label-unit">天</span>\n' +
                                    '                 </div>\n' +
                                    '             </div>\n' +
                                    '         </div>';
                                var wyfStr = '<div class="layui-form-item">\n' +
                                    '             <div class="layui-inline">\n' +
                                    '                 <label class="layui-form-label">计费周期：</label>\n' +
                                    '                 <span style="float: left; line-height: 27px;">固定天数：</span>\n' +
                                    '                 <div style="width: 110px;" class="layui-input-inline">\n' +
                                    '                     <input type="number" name="jfzq-days" value="365" lay-verify="" autocomplete="off"\n' +
                                    '                            class="layui-input">\n' +
                                    '                     <span class="input-label-unit">天</span>\n' +
                                    '                 </div>\n' +
                                    '             </div>\n' +
                                    '         </div>';
                                var str = '<div class="extra-content ' + val + '-content"  data-id="' + val + '">\n' +
                                    '          <fieldset class="layui-elem-field">\n' +
                                    '              <legend>' + title + '</legend>\n' +
                                    '              <div class="layui-field-box">\n' +
                                    '                  <div class="layui-form-item">\n' +
                                    '                      <div class="layui-inline">\n' +
                                    '                          <label class="layui-form-label">发票占比：</label>\n' +
                                    '                          <div class="layui-input-inline">\n' +
                                    '                              <input type="number" name="property-fpzb" lay-verify="" autocomplete="off" class="layui-input">\n' +
                                    '                              <span class="input-label-unit">%</span>\n' +
                                    '                          </div>\n' +
                                    '                      </div>\n' +
                                    '                  </div>';
                                // if (val == "669791dac4894160bc8d79b484519e96" || val == "7b05982a081e41deb9b46a1f6f5ed5fa") {
                                //     str += jfzqStr;
                                // } else {
                                str += '          <div class="layui-form-item">\n' +
                                    '                      <div class="layui-inline">\n' +
                                    '                          <label class="layui-form-label">付款周期：</label>\n' +
                                    '                          <div class="layui-input-inline">\n' +
                                    '                              <input type="number" name="payZhouQi" autocomplete="off" class="layui-input">\n' +
                                    '                              <span class="input-label-unit">月</span>\n' +
                                    '                          </div>\n' +
                                    '                      </div>\n' +
                                    '                  </div>\n';
                                // }
                                if (val == "669791dac4894160bc8d79b484519e96" || val == "7b05982a081e41deb9b46a1f6f5ed5fa") {
                                    str += lnfStr;
                                } else {
                                    str += wyfStr;
                                }
                                str += '           <div class="layui-form-item">\n' +
                                    '                      <div class="layui-inline">\n' +
                                    '                          <label class="layui-form-label">收费日期：</label>\n' +
                                    '                          <div class="layui-input-inline" style="height:25px;">\n' +
                                    '                              <select name="sfrq" lay-filter="sfrq">\n' +
                                    '                                  <option value="0" selected="">提前日收费</option>\n' +
                                    '                                  <option value="1">固定日收费</option>\n' +
                                    '                              </select>\n' +
                                    '                          </div>\n' +
                                    '                          <div class="layui-input-inline">\n' +
                                    '                              <input type="number" name="payRiQi" autocomplete="off" class="layui-input">\n' +
                                    '                              <span class="input-label-unit">天</span>\n' +
                                    '                          </div>\n' +
                                    '                      </div>\n' +
                                    '                  </div>\n';
                                str += '<div class="layui-form-item">\n' +
                                    '       <div class="layui-inline">\n' +
                                    '           <label class="layui-form-label">付款提醒：</label>\n' +
                                    '           <span style="float: left; line-height: 27px;">付款日前：</span>\n' +
                                    '           <div style="width: 110px;" class="layui-input-inline">\n' +
                                    '               <input type="number" name="wy-pay-tx-days" value="1" lay-verify="" autocomplete="off"\n' +
                                    '                      class="layui-input">\n' +
                                    '               <span class="input-label-unit">天</span>\n' +
                                    '           </div>\n' +
                                    '       </div>\n' +
                                    '   </div>';
                                var sffsStr = '       <div class="layui-form-item">\n' +
                                    '                       <div class="layui-inline">\n' +
                                    '                           <label class="layui-form-label">收费方式：</label>\n' +
                                    '                           <div class="layui-input-inline">\n' +
                                    '                               <select name="sfje" lay-filter="sfje">\n' +
                                    '                                   <option value="0" selected="">固定收费</option>\n' +
                                    '                                   <option value="2">按面积收费</option>\n' +
                                    '                               </select>\n' +
                                    '                           </div>\n' +
                                    /*'                           <div class="layui-input-inline">\n' +
                                    '                               <input type="number" name="payJinE" autocomplete="off" class="layui-input">\n' +
                                    '                               <span class="input-label-unit">元/月</span>\n' +
                                    '                           </div>\n' +*/
                                    '                       </div>\n' +
                                    '                  </div>\n';
                                var dwStr = "元/月";
                                if (val == "669791dac4894160bc8d79b484519e96" || val == "7b05982a081e41deb9b46a1f6f5ed5fa") {
                                    dwStr = "元/㎡·天";
                                } else {
                                    str += sffsStr;
                                }
                                str += '           <div class="layui-form-item">\n' +
                                    '                       <div class="layui-inline">\n' +
                                    '                           <label class="layui-form-label">默认价格：</label>\n' +
                                    '                           <div class="layui-input-inline" style="width: 320px;">\n';
                                if (val == "669791dac4894160bc8d79b484519e96" || val == "7b05982a081e41deb9b46a1f6f5ed5fa") {
                                    str += '<input type="radio" name="' + val + '-unit-price" lay-filter="' + val + '-unit-price" value="-1" title="固定价格" checked="checked">';
                                    str += '                           <div class="layui-input-inline ' + val + '-fixed-price" style="display: none; position: absolute; right: 0;">\n' +
                                        '                               <input type="number" name="payFixedJinE" autocomplete="off" class="layui-input">\n' +
                                        // '                               <span class="input-label-unit input-label-unit-flag">元/年</span>\n' +
                                        '                           </div>' +
                                        '                           <div class="layui-input-inline ' + val + '-fixed-price" style="display: none; position: absolute; right: -100px; width: 100px;">' +
                                        '                               <select name="ln-sfdw" lay-filter="ln-sfdw">\n' +
                                        '                                   <option value="0" selected="">元/年</option>\n' +
                                        '                                   <option value="1">元/㎡</option>\n' +
                                        '                               </select>' +
                                        '                           </div>\n' +
                                        '<br>\n';
                                }
                                str += '<input type="radio" name="' + val + '-unit-price" lay-filter="' + val + '-unit-price" value="0" title="自定义" checked="checked">';
                                str += '                           <div class="layui-input-inline ' + val + '-diy-price" style="position: absolute; right: 0;">\n' +
                                    '                               <input type="number" name="payJinE" autocomplete="off" class="layui-input">\n' +
                                    '                               <span class="input-label-unit input-label-unit-flag">' + dwStr + '</span>\n' +
                                    '                           </div>\n';
                                if (!!priceList) {
                                    for (var i = 0; i < priceList.length; i++) {
                                        str += '<br><input type="radio" name="' + val + '-unit-price" lay-filter="' + val + '-unit-price" value="' + priceList[i].ID + '" data-price="' + priceList[i].PRICE_TYPE + '" title="' + priceList[i].PRICE_NAME + '">（' + priceList[i].PRICE_TYPE + '<span class="input-label-unit-flag">' + dwStr + '</span>' + '）';
                                    }
                                }

                                str += '                           </div>\n' +
                                    '                       </div>\n' +
                                    '                  </div>\n';
                                str += '                <div class="layui-form-item">\n' +
                                    '                       <div class="layui-inline">\n' +
                                    '                           <label class="layui-form-label">备注信息：</label>\n' +
                                    '                           <div class="layui-input-inline" style="width: 310px;">\n' +
                                    '                               <textarea name="property-info" lay-verify="" autocomplete="off" class="layui-textarea"></textarea>\n' +
                                    '                           </div>\n' +
                                    '                       </div>\n' +
                                    '                   </div>' +
                                    '              </div>\n' +
                                    '          </fieldset>\n' +
                                    '      </div>';

                                $(".quote-property-info").find(".layui-input-extra-content").append(str);

                                form.on('radio(' + val + '-unit-price)', function (data) {
                                    if (data.value == "-1") {
                                        $("." + val + "-diy-price").hide();
                                        $("." + val + "-fixed-price").css("display", "inline");
                                    } else if (data.value == "0") {
                                        $("." + val + "-fixed-price").hide();
                                        $("." + val + "-diy-price").css("display", "inline");
                                    } else {
                                        $("." + val + "-fixed-price").hide();
                                        $("." + val + "-diy-price").hide();
                                    }
                                });

                                form.render();
                                break;
                        }
                    }
                });

                $(".extra-content").each(function (index, d) {
                    if (property.PROPERTY_TYPE_ID == $(d).data("id")) {
                        $(d).find("input[name='property-fpzb']").val(property.PROPERTY_FPZB);

                        if (property.PROPERTY_TYPE_ID == "a14e6f2e190e4492badac72e9b42152e") {
                            $(d).find("input[name='payZhouQi']").val(property.PAY_DATE);
                            $(d).find("select[name='w-sffs']").val(property.CHARGE_TYPE);
                            if (property.CHARGE_TYPE == "0") {
                                $(d).find("select[name='w-sffs']").parent().parent().find(".input-label-unit").html("元/月");
                                $(".w-sffs-content").css("display", "none");
                                $(".w-choose-price").css("display", "none");
                                $(".sb-setting-class").hide();
                                $(".w-sfrq-content-cb").hide();
                                $(".w-sfrq-content-gd").show();
                                $(".w-default-price").hide();
                                $(".w-sfrq-content-js-other").hide();
                                $(".w-sfrq-content-js").hide();
                                $(".w-sfrq-content-js-sfrq").show();
                                $(".w-diy-price").show();
                            } else if (property.CHARGE_TYPE == "1") {
                                $(d).find("select[name='w-sffs']").parent().parent().find(".input-label-unit").html("元/吨");
                                $(".w-sffs-content").css("display", "inline-block");
                                $(".w-choose-price").css("display", "block");
                                $(".w-sffs-content").empty();
                                $(".w-default-price").empty();
                                $(".w-sfrq-content-js-other").show();
                                $(".w-sfrq-content-js").hide();
                                change.wSffsChange();

                                if (property.IS_DEFAULT == "0") {
                                    $("input:radio[name='w-unit-price'][value='0']").prop('checked', true);
                                    $(".w-default-price").fadeOut(300);
                                    $(".w-diy-price").fadeIn(300);
                                } else if (property.IS_DEFAULT == "-1") {
                                    $("input:radio[name='w-unit-price'][value='-1']").prop('checked', true);
                                    $(".w-diy-price").fadeOut(300);
                                    $(".w-default-price").fadeIn(300);
                                } else if (property.IS_DEFAULT != "-1" && property.IS_DEFAULT != "0") {
                                    $("input:radio[name='w-unit-price'][value='" + property.DEFAULT_ID + "']").prop('checked', true);
                                    $(".w-diy-price").fadeOut(300);
                                    $(".w-default-price").fadeIn(300);
                                }

                            } else if (property.CHARGE_TYPE == "3") {
                                $(d).find("select[name='w-sffs']").parent().parent().find(".input-label-unit").html("元/吨");
                                $(".w-sffs-content").css("display", "inline-block");
                                $(".w-choose-price").css("display", "block");
                                $(".w-sffs-content").empty();
                                $(".w-default-price").empty();
                                change.wSffsChange();
                                $(".w-sfrq-content-js-other").hide();
                                $(".w-sfrq-content-js").show();
                            }
                            $(d).find("input[name='payFangShi']").val(property.CHARGE_PRICE);
                            $(d).find("select[name='w-sfrq']").val(property.CHARGE_DATE_TYPE);
                            if (property.CHARGE_DATE_TYPE == "0") {
                                $(d).find("select[name='w-sfrq']").parent().parent().find(".input-label-unit").html("天");
                            } else if (property.CHARGE_DATE_TYPE == "1") {
                                $(d).find("select[name='w-sfrq']").parent().parent().find(".input-label-unit").html("日");
                            }
                            $(d).find("input[name='w-payRiQi']").val(property.CHARGE_DATE);
                            $(d).find("textarea[name='property-info']").val(property.INFO);
                            $(d).find("input[name='water-late-fee']").val(property.LATE_FEE);
                            $(d).find("input[name='water-late-fee-days']").val(property.LATE_FEE_DAYS);
                            $(d).find("input[name='water-pay-tx-days']").val(property.PAY_TX_DAYS);

                        } else if (property.PROPERTY_TYPE_ID == "ddcf9b35bbe04cd88834e21c1fd74f32") {
                            $(d).find("input[name='payZhouQi']").val(property.PAY_DATE);
                            $(d).find("select[name='e-sffs']").val(property.CHARGE_TYPE);
                            if (property.CHARGE_TYPE == "0") {
                                $(d).find("select[name='e-sffs']").parent().parent().find(".input-label-unit").html("元/月");
                                $(".e-sffs-content").css("display", "none");
                                $(".e-choose-price").css("display", "none");
                                $(".db-setting-class").hide();
                                $(".e-sfrq-content-cb").hide();
                                $(".e-sfrq-content-gd").show();
                                $(".e-default-price").hide();
                                $(".e-sfrq-content-js-other").hide();
                                $(".e-sfrq-content-js").hide();
                                $(".e-sfrq-content-js-sfrq").show();
                                $(".e-diy-price").show();
                            } else if (property.CHARGE_TYPE == "1") {
                                $(d).find("select[name='e-sffs']").parent().parent().find(".input-label-unit").html("元/度");
                                $(".e-sffs-content").css("display", "inline-block");
                                $(".e-choose-price").css("display", "block");
                                $(".e-sffs-content").empty();
                                $(".e-default-price").empty();
                                change.eSffsChange();
                                $(".e-sfrq-content-js-other").show();
                                $(".e-sfrq-content-js").hide();
                                if (property.IS_DEFAULT == "0") {
                                    $("input:radio[name='e-unit-price'][value='0']").prop('checked', true);
                                    $(".e-default-price").fadeOut(300);
                                    $(".e-diy-price").fadeIn(300);
                                } else if (property.IS_DEFAULT == "-1") {
                                    $("input:radio[name='e-unit-price'][value='-1']").prop('checked', true);
                                    $(".e-diy-price").fadeOut(300);
                                    $(".e-default-price").fadeIn(300);
                                } else if (property.IS_DEFAULT != "-1" && property.IS_DEFAULT != "0") {
                                    $("input:radio[name='e-unit-price'][value='" + property.DEFAULT_ID + "']").prop('checked', true);
                                    $(".e-diy-price").fadeOut(300);
                                    $(".e-default-price").fadeIn(300);
                                }
                            } else if (property.CHARGE_TYPE == "3") {
                                $(d).find("select[name='e-sffs']").parent().parent().find(".input-label-unit").html("元/度");
                                $(".e-sffs-content").css("display", "inline-block");
                                $(".e-choose-price").css("display", "block");
                                $(".e-sffs-content").empty();
                                $(".e-default-price").empty();
                                change.eSffsChange();
                                $(".e-sfrq-content-js-other").hide();
                                $(".e-sfrq-content-js").show();
                            }
                            $(d).find("input[name='payFangShi']").val(property.CHARGE_PRICE);
                            $(d).find("select[name='e-sfrq']").val(property.CHARGE_DATE_TYPE);
                            if (property.CHARGE_DATE_TYPE == "0") {
                                $(d).find("select[name='e-sfrq']").parent().parent().find(".input-label-unit").html("天");
                            } else if (property.CHARGE_DATE_TYPE == "1") {
                                $(d).find("select[name='e-sfrq']").parent().parent().find(".input-label-unit").html("日");
                            }
                            $(d).find("input[name='e-payRiQi']").val(property.CHARGE_DATE);
                            $(d).find("textarea[name='property-info']").val(property.INFO);
                            $(d).find("input[name='power-late-fee']").val(property.LATE_FEE);
                            $(d).find("input[name='power-late-fee-days']").val(property.LATE_FEE_DAYS);
                            $(d).find("input[name='power-pay-tx-days']").val(property.PAY_TX_DAYS);

                        } else if (property.PROPERTY_TYPE_ID == "669791dac4894160bc8d79b484519e96" || property.PROPERTY_TYPE_ID == "7b05982a081e41deb9b46a1f6f5ed5fa") {
                            $(d).find("input[name='jfzqStartMonth']").val(property.DATE_START_MONTH);
                            $(d).find("input[name='jfzqStartDay']").val(property.DATE_START_DAY);
                            $(d).find("input[name='jfzqEndMonth']").val(property.DATE_END_MONTH);
                            $(d).find("input[name='jfzqEndDay']").val(property.DATE_END_DAY);
                            $(d).find("input[name='payZhouQi']").val(property.PAY_DATE);
                            $(d).find("select[name='sfrq']").val(property.CHARGE_DATE_TYPE);
                            $(d).find("select[name='ln-sfdw']").val(property.LN_UNIT);
                            if (property.CHARGE_DATE_TYPE == "0") {
                                $(d).find("select[name='sfrq']").parent().parent().find(".input-label-unit").html("天");
                            } else if (property.CHARGE_DATE_TYPE == "1") {
                                $(d).find("select[name='sfrq']").parent().parent().find(".input-label-unit").html("日");
                            }
                            $(d).find("input[name='payRiQi']").val(property.CHARGE_DATE);
                            $(d).find("textarea[name='property-info']").val(property.INFO);
                            if (property.IS_DEFAULT == "0" && property.DEFAULT_ID != "-1") {
                                $(d).find("input:radio[value='0']").prop('checked', true);
                                $(d).find("input[name='payJinE']").val(property.CHARGE_PRICE);
                                $("." + property.PROPERTY_TYPE_ID + "-fixed-price").hide();
                                $("." + property.PROPERTY_TYPE_ID + "-diy-price").css("display", "inline");
                            } else if (property.IS_DEFAULT == "0" && property.DEFAULT_ID == "-1") {
                                $(d).find("input:radio[value='-1']").prop('checked', true);
                                $(d).find("input[name='payFixedJinE']").val(property.CHARGE_PRICE);
                                $("." + property.PROPERTY_TYPE_ID + "-diy-price").hide();
                                $("." + property.PROPERTY_TYPE_ID + "-fixed-price").css("display", "inline");
                            } else if (property.IS_DEFAULT == "1" && property.DEFAULT_ID != "-1") {
                                $(d).find("input:radio[value='" + property.DEFAULT_ID + "']").prop('checked', true);
                                $("." + property.PROPERTY_TYPE_ID + "-fixed-price").hide();
                                $("." + property.PROPERTY_TYPE_ID + "-diy-price").hide();
                            }
                            $(d).find("input[name='wy-pay-tx-days']").val(property.PAY_TX_DAYS);
                            $(d).find("input[name='jfzq-days']").val(property.PAY_DAYS);

                        } else {
                            $(d).find("input[name='payZhouQi']").val(property.PAY_DATE);
                            $(d).find("select[name='sfrq']").val(property.CHARGE_DATE_TYPE);
                            $(d).find("select[name='sfje']").val(property.CHARGE_TYPE);
                            if (property.CHARGE_TYPE == "2") {
                                $(d).find(".input-label-unit-flag").html("元/㎡·天");
                            }
                            if (property.CHARGE_DATE_TYPE == "0") {
                                $(d).find("select[name='sfrq']").parent().parent().find(".input-label-unit").html("天");
                            } else if (property.CHARGE_DATE_TYPE == "1") {
                                $(d).find("select[name='sfrq']").parent().parent().find(".input-label-unit").html("日");
                            }
                            $(d).find("input[name='payRiQi']").val(property.CHARGE_DATE);
                            $(d).find("textarea[name='property-info']").val(property.INFO);
                            if (property.IS_DEFAULT == "0" && property.DEFAULT_ID != "-1") {
                                $(d).find("input:radio[value='0']").prop('checked', true);
                                $(d).find("input[name='payJinE']").val(property.CHARGE_PRICE);
                                $("." + property.PROPERTY_TYPE_ID + "-fixed-price").hide();
                                $("." + property.PROPERTY_TYPE_ID + "-diy-price").css("display", "inline");
                            } else if (property.IS_DEFAULT == "0" && property.DEFAULT_ID == "-1") {
                                $(d).find("input:radio[value='-1']").prop('checked', true);
                                $(d).find("input[name='payFixedJinE']").val(property.CHARGE_PRICE);
                                $("." + property.PROPERTY_TYPE_ID + "-diy-price").hide();
                                $("." + property.PROPERTY_TYPE_ID + "-fixed-price").css("display", "inline");
                            } else if (property.IS_DEFAULT == "1" && property.DEFAULT_ID != "-1") {
                                $(d).find("input:radio[value='" + property.DEFAULT_ID + "']").prop('checked', true);
                                $("." + property.PROPERTY_TYPE_ID + "-fixed-price").hide();
                                $("." + property.PROPERTY_TYPE_ID + "-diy-price").hide();
                            }
                            $(d).find("input[name='wy-pay-tx-days']").val(property.PAY_TX_DAYS);
                            $(d).find("input[name='jfzq-days']").val(property.PAY_DAYS);

                        }

                    }
                });

            }
        }

        // 表初始读数
        var initRead = data.initRead;
        if (!!initRead) {
            for (var i = 0; i < initRead.length; i++) {
                $(".w-sbds-list .layui-inline").each(function () {
                    if (initRead[i].HYDROPOWER_ID == $(this).data("bid")) {
                        $(this).find("input[name='dqds']").val(initRead[i].INIT_READ);
                        $(this).find("input[name='cbrq']").val(initRead[i].INIT_READ_TIME);
                    }
                });
                $(".e-dbds-list .layui-inline").each(function () {
                    if (initRead[i].HYDROPOWER_ID == $(this).data("bid")) {
                        $(this).find("input[name='dqds']").val(initRead[i].INIT_READ);
                        $(this).find("input[name='cbrq']").val(initRead[i].INIT_READ_TIME);
                    }
                });
            }
        }

        // 表比例
        var bl = data.BL;
        if (!!bl) {
            for (var i = 0; i < bl.length; i++) {
                var obj = bl[i];
                if (obj.TYPE == "ae5806f8184546208411b99e6117eaa2") {
                    $(".w-sbds-list .layui-inline input[name='bl']").each(function () {
                        if (obj.PROJECTID == $(this).data("project")) {
                            $(this).val(obj.W_BL);
                        }
                    });
                } else if (obj.TYPE == "b938139a48ed4344a11a7180b48eede6") {
                    $(".e-dbds-list .layui-inline input[name='bl']").each(function () {
                        if (obj.PROJECTID == $(this).data("project")) {
                            $(this).val(obj.E_BL);
                        }
                    });
                }
            }
        }

        // 生成物业账单
        var propertyBill = data.propertyBill;
        // console.log(propertyBill);
        operate.createPropertyRentDetail();
        $(".container-property-rent-detail-list").html(contract.PROPERTY_BILL_HTML);

        $(".change-unit").html(unitHtml);

        if (data.contract.IF_COLLECTION == 1) {
            collection = 1;
            $("input[name='collection']").prop("checked", true);
        }
        edit.initCollection(data.collectionData);

        form.render();
    },
    // 初始化代收信息
    initCollection: function (data) {
        // console.log(data)
        if (!!data) {
            $(".daishou-box").find("input[name='TX_TEL']").val(data.TX_TEL);
            $(".daishou-box").find("input[name='TX_EMAIL']").val(data.TX_EMAIL);
            $(".daishou-box").find("select[name='BANK_CODE']").val(data.BANK_CODE);

            change.bankCodeChange(Number(data.BANK_CODE));
            if (data.ACCOUNT_TYPE == "01") {
                $("input:radio[name='ACCOUNT_TYPE'][value='00']").attr('checked', 'false');
                $("input:radio[name='ACCOUNT_TYPE'][value='01']").attr('checked', 'true');
            }
            $(".daishou-box").find("input[name='ACCOUNT_NO']").val(data.ACCOUNT_NO);
            $(".daishou-box").find("input[name='ACCOUNT_NAME']").val(data.ACCOUNT_NAME);
            $(".daishou-box").find("select[name='PROVINCE']").val(data.PROVINCE);
            change.provinceChange(data.PROVINCE);
            form.render('select');
            $(".daishou-box").find("select[name='CITY']").val(data.CITY);
            $(".daishou-box").find("input[name='BANK_NAME']").val(data.BANK_NAME);
            if (data.ACCOUNT_TYPE == "01") {
                $("input:radio[name='ACCOUNT_PROP'][value='0']").attr('checked', 'false');
                $("input:radio[name='ACCOUNT_PROP'][value='1']").attr('checked', 'true');
            }
            $(".daishou-box").find("select[name='CURRENCY']").val(data.CURRENCY);
            $(".daishou-box").find("select[name='ID_TYPE']").val(data.ID_TYPE);
            $(".daishou-box").find("input[name='CID']").val(data.ID_CARD);
            $(".daishou-box").find("input[name='TEL']").val(data.TEL);
            $("textarea[name='ZY']").val(data.ABSTRACT);
        }
    }
};
/**
 * 合同变更方法集合
 * 使用： contractChange.function()
 * param: obj传this，调用该方法的对象
 *
 */
var contractChange = {
    // 隐藏变更按钮
    hideTemporaryStorageBtn: function () {
        $(".temporaryStorageBtn").remove();
        $(".submitBtn").remove();
        $(".changeBtn").css("display", "inline-block");
    },
    // 将输入或选择框等设置为不可点击或改变
    initDisabled: function () {
        /*$(".room-select input[name='room']").attr("disabled", "disabled");

        $(".quote-contract-info .contract-setting:first input").attr("disabled", "disabled");
        $(".quote-contract-info .contract-setting:first select").attr("disabled", "disabled");
        $(".quote-contract-info .contract-setting:first textarea").attr("disabled", "disabled");
        $(".quote-contract-info .contract-setting:first a").unbind();
        $(".quote-contract-info .contract-setting:first .contract-setting-left .fa-times-circle").remove();
        $(".quote-contract-info .contract-setting:first .contract-setting-center a").removeAttr("onclick");
        $(".quote-contract-info .contract-setting:first .contract-setting-center i").removeAttr("onclick");
        $(".quote-contract-info .contract-setting:first .contract-setting-right a").removeAttr("onclick");
        $(".quote-contract-info .contract-setting:first .contract-setting-right i").removeAttr("onclick");

        $(".quote-contract-info .contract-setting:first a").hover(function(){
            $(this).css("cursor", "not-allowed");
        });
        $(".quote-contract-info .contract-setting:first i").hover(function(){
            $(this).css("cursor", "not-allowed");
        });
        $(".fa-plus-circle").hover(function(){
            $(this).css("cursor", "pointer");
        });*/


        $(".quote-property-info input").attr("disabled", "disabled");
        $(".quote-property-info select").attr("disabled", "disabled");
        $(".quote-property-info textarea").attr("disabled", "disabled");
        $(".quote-property-detail .quote-title a").remove();
        form.render();
    },
    // 给原始账单赋值
    setOldBill: function (bill) {
        // console.log(bill);
        for (var i = 0; i < bill.length; i++) {
            var b = bill[i];
            if (b.BILL_TYPE == "1") {
                // console.log(b);
                var str = '<li class="rent-detail-item rent-detail-item-yj">\n' +
                    '          <div>\n' +
                    '              <span><input type="checkbox" name="BILL_ID" value="' + b.ID + '" checked></span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + b.BILL_NAME + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + b.PAY_DATE + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span> - </span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span class="real-zjje">' + b.TOTAL_PRICE + '</span>\n';
                if (b.ALLOT_BILL == "0") {
                    str += "开发票";
                } else if (b.ALLOT_BILL == "1") {
                    str += "不开发票";
                }
                str += '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + b.INFO + '</span>\n' +
                    '          </div>\n' +
                    '      </li>';
                $(".container-rent-detail-list-old").append(str);
            } else if (b.BILL_TYPE == "0") {
                // console.log(b);
                var str = '<li class="rent-detail-item">\n' +
                    '          <div>\n' +
                    '              <span><input type="checkbox" name="BILL_ID" value="' + b.ID + '" checked></span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + b.START_DATE + ' - ' + b.END_DATE + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + b.PAY_DATE + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + b.LATE_FEE + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span class="real-zjje">' + b.TOTAL_PRICE + '</span>\n';
                if (b.ALLOT_BILL == "0") {
                    str += "开发票";
                } else if (b.ALLOT_BILL == "1") {
                    str += "不开发票";
                }
                str += '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + b.INFO + '</span>\n' +
                    '          </div>' +
                    '       </li>';
                $(".container-rent-detail-list-old").append(str);
            } else if (b.BILL_TYPE == "2") {
                var str = '<li class="rent-detail-item">\n' +
                    '          <div>\n' +
                    '              <span><input type="checkbox" name="BILL_ID" value="' + b.ID + '" checked></span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>(' + b.BILL_NAME + ')' + b.START_DATE + ' - ' + b.END_DATE + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + b.PAY_DATE + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>-</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span class="real-zjje">' + b.TOTAL_PRICE + '</span>\n';
                if (b.ALLOT_BILL == "0") {
                    str += "开发票";
                } else if (b.ALLOT_BILL == "1") {
                    str += "不开发票";
                }
                str += '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + b.INFO + '</span>\n' +
                    '          </div>' +
                    '       </li>';
                $(".container-rent-detail-list-old").append(str);
            }
        }
        form.render();
        contractChange.initQx();
    },
    //
    initQx: function () {
        form.on('checkbox(zf-qx)', function(data){
            if (data.elem.checked) {
                if ($("input[name='BILL_ID']").length == $("input[name='BILL_ID']").filter(':not(:checked)').length) {  // 复选框长度和没选中的个数一样 -> 全选 , .not(':checked').length 也可以。
                    $("input[name='BILL_ID']").prop('checked', true);
                } else {   // 如果有选中个数，-> 反选
                    $("input[name='BILL_ID']").each(function () {
                        $(this).prop('checked', $(this).is(':checked') ? false : true);
                    });
                }
            } else {
                $("input[name='BILL_ID']").prop('checked', false);  // 如控制键取消选中，剩余的checkbox也取消选中
            }

            form.render('checkbox');
        });
    }
};